<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加员工</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css">
    <style>
        *{
            border-radius: 0 !important;
        }
        .register-box{
            margin-top: 150px;
        }
        .login-panel{
            padding:10px;
            background: #fff;
        }
        .register-title{
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            padding: 20px;
            color: #0d8ddb;
        }
    </style>
</head>
<body>
<!--登录/注册框-->
<div class="layui-container ">
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-md-offset3 login-panel">
            <form class="layui-form layui-form-pane">
                <div class="layui-form-item">
<!--                    <h4 class="register-title">管理员添加</h4>-->
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <i>用户名</i>
                    </label>
                    <div class="layui-input-block">
                        <input type="text" name="username"
                               class="layui-input" placeholder="请输入用户名"
                               required lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <i>密码</i>
                    </label>
                    <div class="layui-input-block">
                        <input type="password" name="password"
                               class="layui-input" placeholder="请输入密码"
                               required lay-verify="required" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <i>注册时间</i>
                    </label>
                    <div class="layui-input-block">
                        <input type="text" id="addtime" name="addtime"
                               class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <i>状态信息</i>
                    </label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" title='正常' checked>
                        <input type="radio" name="status" value="1" title="封禁">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-normal layui-btn-fluid"
                            lay-submit lay-filter="formRegister">添加</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../res/js/config.js"></script>
<script src="../res/layui/layui.js"></script>
<script>
    layui.use(function(){
        var ele = layui.element;
        var form = layui.form;
        var $ = layui.jquery;
        //日期组件
        var laydate = layui.laydate;

        // 渲染  date 只有日期  time只有时间  datetime 日期时间
        laydate.render({
            elem: '#addtime',
            type: 'datetime',
            pattern:'yyyy-MM-dd HH:mm:ss'
        });

        //绑定表单事件 formRegister
        form.on('submit(formRegister)',function(data){
            var field = data.field; // 获取表单字段值
            console.log(field); //form表单中的值
            // 此处可执行 Ajax 等操作 (请求后台接口)
            $.get("http://localhost:8989/admin/register",field,function(resp){
                if(resp.success){
                    //
                    location.href='emp-add.html';
                }else{
                    //弹出提示错误信息
                    layer.alert(resp.msg,{icon:2})
                }
            })
            return false; // 阻止默认 form 跳转
        })

    })
</script>
</body>
</html>